package com.feihong.yw189.paidan.qiangdanservice.notification;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

/**
 * Created by admin on 2018/2/3.
 */

public class NotifyUtil {
    public static Context context;

    public static NotificationManager getNm() {
        return nm;
    }

    private static NotificationManager nm;
    public static void init(Context context1){
        context = context1;
        nm = (NotificationManager) context1
                .getSystemService(Activity.NOTIFICATION_SERVICE);
    }

    public static BaseBuilder buildSimple(int id, int smallIcon, CharSequence contentTitle , CharSequence contentText, PendingIntent contentIntent){
        BaseBuilder builder = new BaseBuilder();
        builder.setBase(smallIcon,contentTitle,contentText)
                .setId(id)
                .setContentIntent(contentIntent);
        return builder;
    }
    public static void notify(int id,Notification notification){
        nm.notify(id,notification);
    }

    public static PendingIntent buildIntent(Class clazz){
        int flags = PendingIntent.FLAG_UPDATE_CURRENT;
        Intent intent = new Intent(NotifyUtil.context, clazz);
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_NEW_TASK);
        //intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        //intent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED|Intent.FLAG_ACTIVITY_CLEAR_TOP );
        PendingIntent pi = PendingIntent.getActivity(NotifyUtil.context, 0, intent, flags);
        return pi;
    }

    public static void cancel(int id){
        if(nm!=null){
            nm.cancel(id);
        }
    }

    public static void cancelAll(){
        if(nm!=null){
            nm.cancelAll();
        }
    }
}
